import numpy as np

# 定义原始数据集
data = {
    '姓名': ['张三', '李四', '王五', '赵六'],
    'X1_年龄': [25, 36, 45, 55],
    'X2_收入': [10000, 50000, 80000, 100000]
}

# 提取特征数据（跳过姓名列）
X1 = np.array(data['X1_年龄'], dtype=np.float64)  # 年龄特征
X2 = np.array(data['X2_收入'], dtype=np.float64)  # 收入特征

# 定义最小最大归一化函数
def min_max_normalize(feature):
    feature_min = np.min(feature)
    feature_max = np.max(feature)
    return (feature - feature_min) / (feature_max - feature_min)

# 对年龄和收入分别进行归一化
X1_normalized = min_max_normalize(X1)
X2_normalized = min_max_normalize(X2)

# 合并归一化结果到原始数据
data_normalized = {
    '姓名': data['姓名'],
    'X1_年龄(归一化)': X1_normalized.round(4),  # 保留4位小数
    'X2_收入(归一化)': X2_normalized.round(4)
}

# 打印归一化结果
print("原始数据：")
for key, value in data.items():
    print(f"{key}: {value}")

print("\n归一化后数据：")
for key, value in data_normalized.items():
    print(f"{key}: {value}")

